-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(tests): adds basic testing support #8
Conversation
__mocks__/fs.ts
Outdated
@@ -0,0 +1,5 @@ | |||
const fs = jest.genMockFromModule("fs") as any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implement correct type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have @types/node
which should include fs
(https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/fs.d.ts#L1595). what was the error you were getting here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw this on S/O: https://stackoverflow.com/questions/52113681/how-can-i-mock-a-third-party-node-module-function-using-jest-with-typescript
Looks like they're doing slightly the same thing.
jest.config.js
Outdated
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any other config we can think of for now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing at the moment. Thoughts on adding this to the package.json
instead of a separate file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few suggestions. Looking 🎸 though!
__mocks__/fs.ts
Outdated
@@ -0,0 +1,5 @@ | |||
const fs = jest.genMockFromModule("fs") as any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have @types/node
which should include fs
(https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/fs.d.ts#L1595). what was the error you were getting here?
@@ -1 +1 @@ | |||
export {run} from '@oclif/command' | |||
export { run } from "@oclif/command"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we have prettier set for this? If not we should (typically spaces before curlies and single quotes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, this is a global prettier config I'm using - we don't have one on the project yet.
const templateLocation = getTemplateLocation(); | ||
|
||
expect(templateLocation).toEqual(`HYGEN_TMPLS=/custom/path/to/_templates`); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎸
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great test 👏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, I think we're close to approving, just a few questions
|
||
fs.existsSync = () => true; | ||
|
||
module.exports = fs; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are your thoughts on mocking the function instead of mocking the whole module?
const mock = jest.spyOn(fs, 'readFileSync'); // spy on fs.readFileSync()
mock.mockImplementation(() => JSON.stringify({ name: 'myname' }));
Would that a better idea? And would it solve the type issue we're currently trying to solve?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, gotcha. Well, I don't think we should hold this back for that reason.
Ping me when you think this is ready to go and I'll approve!
jest.config.js
Outdated
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing at the moment. Thoughts on adding this to the package.json
instead of a separate file?
const templateLocation = getTemplateLocation(); | ||
|
||
expect(templateLocation).toEqual(`HYGEN_TMPLS=/custom/path/to/_templates`); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great test 👏
const hasTemplates = fs.existsSync(theirTemplatePath); | ||
|
||
export const getTemplateLocation = (): string => | ||
hasTemplates ? theirTemplatePath : DEFAULT_TEMPLATE_PATH; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love how clean this is! 👍 💯 Nice work!
3e1c496
to
0db34a2
Compare
0db34a2
to
0e73751
Compare
@alvincrespo we updated the CircleCI config so that I can leverage this in my tests |
@all-contributors please add @alvincrespo for code, doc, test and review |
I've put up a pull request to add @alvincrespo! 🎉 |
@all-contributors please add @cball for infra, ideas, and review |
I've put up a pull request to add @cball! 🎉 |
* BREAKING CHANGE: modify how generate command works * docs(contrib): add ci and update generate command docs (#6) * feat: update README and add CONTRIBUTING * fix: update generate command args * feat: update docs with new generate command info * docs: add jsjoeio as a contributor (#13) * docs: update README.md * docs: create .all-contributorsrc * chore: add @semantic-release/npm & .../git plugins (#14) * feat: add semantic-release/git * feat: add npm plugin as well * chore(templates): add issue template (#15) * Update issue templates Add a simple issue report template * Create pull_request_template.md add PR template * docs: add cmejet as a contributor (#16) * docs: update README.md * docs: update .all-contributorsrc * change name to bug instead of issue It makes more sense to call this bug because it's a bug report issue template * Create feature_request.md add feature request template * Update and rename issue-report.md to bug_ report.md * chore: clean up template Remove stuff specific to Gatsby * feat(command): add init script (#11) * feat: add init command * feat: add node types * feat: add write to package.json in init * refactor: write to package.json * feat: add install eb-scripts line * refactor: change name of vars * chore: update oclif.manifest and README * Update src/commands/init.ts Co-Authored-By: Chris Ball <chris@echobind.com> * fix: modify order of updatedScripts * docs: add alvincrespo as a contributor (#22) * docs: update README.md * docs: update .all-contributorsrc * feat(tests): adds basic testing support (#8) * first commit * moar progress * passing tests * reorg deps * cast as any properly * updating per review * move jest config into package.json * feat: update circleci config * docs: add cball as a contributor (#23) * docs: update README.md * docs: update .all-contributorsrc * chore(project): add prettier, eslint and husky (#26) * feat: add prettier and husky * chore: add eslint and deps * chore: add eslint plugins prettier and eb * feat(testing): add integration test for generate command (#24) * fix: add back in semantic release plugins * fix: add jest config and install fs-extra * feat: add makeTempDir and removeTempDir utils * wip: add initial generate test * feat: add util fn to check if dir exists * refactor: change names temp dir fns * refactor: add index to simplify exports * wip: add test with oclif * feat: add checkFileExists util * chore: update deps * chore: add checkFileExists to index * wip: almost there * wip: generate test * feat: add test for no flags * wip: add oclif test * feat: write snapshot test for generate error * chore: clean up deps * wip: add test to check custom templates * feat: add test to check using custom templates * refactor: use copyFile instead of writeFile * feat: update snapshot and get test passing default * refactor: create tests/helpers and move template * chore: update order of types in package.json * refactor: remove proxy fse fns * refactor: clean up getTemplateLocation * docs: add jeffreyzhen as a contributor (#35) * docs: update README.md * docs: update .all-contributorsrc * refactor: update CONTRIBUTING PR process * refactor: update PR template to add check for base branch * chore(release): add commit-analyzer and release-notes-generator (#30) * feat: add commit analyzer and rel not generator semantic release * fix: only release if semantic-release passes * refactor: use npm ci in circleci * refactor: use yarn in circleci config * fix: typo in release section * fix: switch back to npm in config * fix: change back to npm install * feat(generate, init): add support for react-typescript (#36) * fix: add back in semantic release plugins * fix: add jest config and install fs-extra * feat: add makeTempDir and removeTempDir utils * feat: add util fn to check if dir exists * refactor: change names temp dir fns * wip: add test with oclif * feat: add checkFileExists util * wip: almost there * wip: generate test * feat: add test for no flags * wip: add oclif test * feat: write snapshot test for generate error * chore: clean up deps * wip: add test to check custom templates * feat: add test to check using custom templates * refactor: use copyFile instead of writeFile * refactor: create tests/helpers and move template * chore: update order of types in package.json * refactor: remove proxy fse fns * feat: add initial init test * wip: get tests setup for init * feat: finish yarn lock * feat: add test for init without flag * feat: add validProjectTypes to init, and test * fix: run tests sequentially with --runInBand * refactor: clean up unused tests init * fix: update README formatting * fix: update getTemplateLocation test * refactor: fix getTemplateLocation test * refactor: move afterEach and afterAll into describe block * fix: switch to yarn * fix: update test description * docs: add comment about dup import of fn * fix: update test description in init.test * refactor: use flag or args for init, remove -p * chore: update README * wip: update init and test to make project required * fix: tell jest to ignore lib * fix: update init tests and snap * feat: add path flag to generate and update temps * fix: update generate to throw on no args * fix: remove extra space in templates * fix: update test description * fix: update log statement in generate * fix: remove other extra space * fix: update old test * fix: update helper template for test * feat: add test for location flag * fix: unskip tests * refactor: remove side effect in last test * feat: add -p to script in init * refactor: unskip and use all tests * fix: update test after rebase * fix: update snapshot after rebase not updating it * feat: add react-typescript-component templates * refactor: improve typings in generate command * refactor: remove old template flag from generate * wip: add test for react-typescript-component * feat: add react-typescript-component as new temp type * fix: typos in react-ts-component template * fix: remove old copyFile fn * feat: add react-typescript to init projects * feat: update snapshots and add test * refactor: require to readFile to prevent caching * fix: remove console.logs * docs: update with new command info * fix: update item in checklist for PR * fix: update circle ci config * fix: switch back to yarn * feat(generate, init): allow user to override path for templates (#33) * fix: add back in semantic release plugins * fix: add jest config and install fs-extra * feat: add makeTempDir and removeTempDir utils * feat: add util fn to check if dir exists * refactor: change names temp dir fns * wip: add test with oclif * feat: add checkFileExists util * wip: almost there * wip: generate test * feat: add test for no flags * wip: add oclif test * feat: write snapshot test for generate error * chore: clean up deps * wip: add test to check custom templates * feat: add test to check using custom templates * refactor: use copyFile instead of writeFile * refactor: create tests/helpers and move template * chore: update order of types in package.json * refactor: remove proxy fse fns * fix: run tests sequentially with --runInBand * fix: update getTemplateLocation test * refactor: fix getTemplateLocation test * chore: update README * fix: update init tests and snap * fix: update generate to throw on no args * fix: update test description * fix: update old test * refactor: remove side effect in last test * feat: add -p to script in init * refactor: unskip and use all tests * fix: update test after rebase * fix: update snapshot after rebase not updating it * fix: errors after rebase * fix: update snapshot * feat(generate, init): add support for react-native-typescript (#37) * feat: add component template * refactor: change name to react-native-typescript * refactor: change name to typescript component * feat: add react-typescript-component to generate * feat: add test for react-native-typescript-component * feat: add react-native-typescript to init * feat: add react-native-typescript screen template * feat: add react-native-typescript-screen to generate * wip: generate screen test * wip: add note about screen template test * feat: add e2e template * feat: add e2e to init command * feat: add e2e to generate * fix: update quotes to double in e2e template * feat: add e2e to react-native-ts and add tset * feat: add e2e template test * fix: update snapshot after changes * feat: add util-typescript-template * feat: add util-typescript to generate and init * fix: add test and default path for utils temp * fix: update generate test * fix: update generate snapshot after new util template * fix: update docs * fix: clean up from comments * fix: comment out skipped test * fix: change component name in test * fix: update version to match npm version * fix: update oclif manifest to match master * fix: update PR template * fix: update bug report * [ci skip]: fix version issue * docs(contrib): add ci and update generate command docs (#6) * feat: update README and add CONTRIBUTING * fix: update generate command args * feat: update docs with new generate command info * chore(templates): add issue template (#15) * Update issue templates Add a simple issue report template * Create pull_request_template.md add PR template * Update and rename issue-report.md to bug_ report.md * feat(command): add init script (#11) * feat: add init command * feat: add node types * feat: add write to package.json in init * refactor: write to package.json * feat: add install eb-scripts line * refactor: change name of vars * chore: update oclif.manifest and README * Update src/commands/init.ts Co-Authored-By: Chris Ball <chris@echobind.com> * fix: modify order of updatedScripts * feat(generate, init): add support for react-typescript (#36) * fix: add back in semantic release plugins * fix: add jest config and install fs-extra * feat: add makeTempDir and removeTempDir utils * feat: add util fn to check if dir exists * refactor: change names temp dir fns * wip: add test with oclif * feat: add checkFileExists util * wip: almost there * wip: generate test * feat: add test for no flags * wip: add oclif test * feat: write snapshot test for generate error * chore: clean up deps * wip: add test to check custom templates * feat: add test to check using custom templates * refactor: use copyFile instead of writeFile * refactor: create tests/helpers and move template * chore: update order of types in package.json * refactor: remove proxy fse fns * feat: add initial init test * wip: get tests setup for init * feat: finish yarn lock * feat: add test for init without flag * feat: add validProjectTypes to init, and test * fix: run tests sequentially with --runInBand * refactor: clean up unused tests init * fix: update README formatting * fix: update getTemplateLocation test * refactor: fix getTemplateLocation test * refactor: move afterEach and afterAll into describe block * fix: switch to yarn * fix: update test description * docs: add comment about dup import of fn * fix: update test description in init.test * refactor: use flag or args for init, remove -p * chore: update README * wip: update init and test to make project required * fix: tell jest to ignore lib * fix: update init tests and snap * feat: add path flag to generate and update temps * fix: update generate to throw on no args * fix: remove extra space in templates * fix: update test description * fix: update log statement in generate * fix: remove other extra space * fix: update old test * fix: update helper template for test * feat: add test for location flag * fix: unskip tests * refactor: remove side effect in last test * feat: add -p to script in init * refactor: unskip and use all tests * fix: update test after rebase * fix: update snapshot after rebase not updating it * feat: add react-typescript-component templates * refactor: improve typings in generate command * refactor: remove old template flag from generate * wip: add test for react-typescript-component * feat: add react-typescript-component as new temp type * fix: typos in react-ts-component template * fix: remove old copyFile fn * feat: add react-typescript to init projects * feat: update snapshots and add test * refactor: require to readFile to prevent caching * fix: remove console.logs * docs: update with new command info * fix: update item in checklist for PR * fix: update circle ci config * fix: switch back to yarn * feat(generate, init): allow user to override path for templates (#33) * fix: add back in semantic release plugins * fix: add jest config and install fs-extra * feat: add makeTempDir and removeTempDir utils * feat: add util fn to check if dir exists * refactor: change names temp dir fns * wip: add test with oclif * feat: add checkFileExists util * wip: almost there * wip: generate test * feat: add test for no flags * wip: add oclif test * feat: write snapshot test for generate error * chore: clean up deps * wip: add test to check custom templates * feat: add test to check using custom templates * refactor: use copyFile instead of writeFile * refactor: create tests/helpers and move template * chore: update order of types in package.json * refactor: remove proxy fse fns * fix: run tests sequentially with --runInBand * fix: update getTemplateLocation test * refactor: fix getTemplateLocation test * chore: update README * fix: update init tests and snap * fix: update generate to throw on no args * fix: update test description * fix: update old test * refactor: remove side effect in last test * feat: add -p to script in init * refactor: unskip and use all tests * fix: update test after rebase * fix: update snapshot after rebase not updating it * fix: errors after rebase * fix: update snapshot * feat(generate, init): add support for react-native-typescript (#37) * feat: add component template * refactor: change name to react-native-typescript * refactor: change name to typescript component * feat: add react-typescript-component to generate * feat: add test for react-native-typescript-component * feat: add react-native-typescript to init * feat: add react-native-typescript screen template * feat: add react-native-typescript-screen to generate * wip: generate screen test * wip: add note about screen template test * feat: add e2e template * feat: add e2e to init command * feat: add e2e to generate * fix: update quotes to double in e2e template * feat: add e2e to react-native-ts and add tset * feat: add e2e template test * fix: update snapshot after changes * feat: add util-typescript-template * feat: add util-typescript to generate and init * fix: add test and default path for utils temp * fix: update generate test * fix: update generate snapshot after new util template * fix: update docs * fix: clean up from comments * fix: comment out skipped test * fix: change component name in test * fix: remove flag from yarn test * fix: update snapshots * fix: updte bin run * fix: update oclif and init snapshot * reactor: export all utils * refactor: move test higher * fix: update snapshots and add runInBand flag to yarn test * fix: update PR template to remove check for next branch
# [2.0.0](v1.0.0...v2.0.0) (2019-11-11) ### Features * **generate, init:** create new release ([#39](#39)) ([c4d4f54](c4d4f54)), closes [#6](#6) [#13](#13) [#14](#14) [#15](#15) [#16](#16) [#11](#11) [#22](#22) [#8](#8) [#23](#23) [#26](#26) [#24](#24) [#35](#35) [#30](#30) [#36](#36) [#33](#33) [#37](#37) [#6](#6) [#15](#15) [#11](#11) [#36](#36) [#33](#33) [#37](#37) ### BREAKING CHANGES * **generate, init:** modify how generate command works
Changes
ts-jest
as a dependencytest
script to runjest
Fixes #1